package com.lighting.common.core.vo;

import com.lighting.common.core.constants.ErrorCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Result<T> {

    private Integer code;

    private String msg = "success";

    private T data;

    public Result() {
    }

    public Result(Integer code) {
        this.code = code;
    }

    public Result(T data) {
        this.data = data;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public Result(Integer code, String msg, T data) {
        this(code, msg);
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(0);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(0, data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result<>(0, msg, data);
    }

    public static <T> Result<T> fail(String msg) {
        return fail(999, msg);
    }

    public static <T> Result<T> fail(Integer code, String msg) {
        return new Result<>(code, msg);
    }

    public static <T> Result<T> fail(ErrorCode errorCode) {
        return fail(errorCode.getCode(), errorCode.getMsg());
    }

    public static <T> Result<T> fail(ErrorCode errorCode, String msg) {
        return fail(errorCode.getCode(), msg);
    }

}
